<?php
class Sosweb_View_Form_CouponForm extends Zend_Form
{
	public function createForm($formType, $categories)
	{
		$title = new Zend_Form_Element_Text('title');	
        $title->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getNotEmptyValidator(), true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(2, 255), true)
        		->setLabel('Tytuł kuponu:')
        		->setDescription('Podaj tytuł kuponu (WYMAGANE)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 255);

        $title->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );
        
		$t_link = new Zend_Form_Element_Text('t_link');	
        $t_link->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(false)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(2, 255), true)	
        		->setLabel('Link tytułu kuponu:')
        		->setDescription('Podaj link do sklepu z kuponem')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 255);

        $t_link->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );

		$content = new Zend_Form_Element_Text('content');	
        $content->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getNotEmptyValidator(), true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(2, 255), true)	
        		->setLabel('Treść kuponu:')
        		->setDescription('Podaj treść kuponu (WYMAGANE)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 255);

        $content->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );
                
		$code = new Zend_Form_Element_Text('code');	
        $code->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getNotEmptyValidator(), true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(2, 100), true)	
        		->setLabel('Kod:')
        		->setDescription('Podaj kod promocyjny (WYMAGANE)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 100);

        $code->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );
        
		$c_link = new Zend_Form_Element_Text('c_link');	
        $c_link->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(false)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(2, 255), true)	
        		->setLabel('Link do produktu:')
        		->setDescription('Podaj link do produktu którego dotyczy kupon')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 255);
	
        $c_link->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );
        
		$posted_date = new Zend_Form_Element_Text('posted_date');	
        $posted_date->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(10, 10), true)	
        		->setLabel('Data dodania kuponu:')
        		->setDescription('Podaj datę dodania kuponu (puste oznacza datę dzisiejszą)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 10);
	
        $posted_date->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );

		$expiry_date = new Zend_Form_Element_Text('expiry_date');	
        $expiry_date->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(10, 10), true)	
        		->setLabel('Data wygaśnięcia kuponu:')
        		->setDescription('Podaj datę wygaśnięcia kuponu (puste oznacza że nie wygasa nigdy)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 10);
	
        $expiry_date->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );
        
        $category_id = new Zend_Form_Element_Select('category_id');	
        $category_id->setLabel('Kategoria kuponu:')
        		->setDescription('Określ kategorię kuponu')
        		->setAttrib('class', '')
        		->setMultiOptions($categories);

        $category_id->setDecorators(
        	array(
        		array('ViewHelper'),
        		array('Errors'),
			    array('Description', array('class' => '')),
			    array('Label', array('class' => '', 'tag' => 'p'))
        	)
        );        

        $file = new Zend_Form_Element_File('logo');
		$file->setLabel('Wybierz obrazek:')
			->setDescription('Wybierz plik logo firmy')
			->setDestination('files/upload')
			->addValidator('Count', false, 1)
			->addValidator('Size', false, 102400)
			->addValidator('Extension', false, 'jpg,png,gif');
        
		$password = new Zend_Form_Element_Password('password');	
        $password->addFilter('StringTrim')
        		->addFilter('StripTags')
        		->setRequired(true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getNotEmptyValidator(), true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getAlnumValidator(), true)
        		->addValidator(Sosweb_Util_Validator_CustomValidator::getStringLengthValidator(6, 20), true)	
        		->setLabel('Hasło:')
        		->setDescription('Wprowadź swoje hasło (WYMAGANE)')
        		->setAttrib('class', '')
        		->setAttrib('maxlength', 20);

        $id = new Zend_Form_Element_Hidden('id');
        $id->setValue('0');
        $id->setDecorators(
        	array(
        		array('ViewHelper')
        	)
        );
        
        $form_id = new Zend_Form_Element_Hidden('form_id');
        $form_id->setValue('2');
        $form_id->setDecorators(
        	array(
        		array('ViewHelper')
        	)
        );
                
        $token = new Zend_Form_Element_Hidden('token');
                
        if ($formType == 'add')
        {
	        $save_button = new Zend_Form_Element_Submit('save_button');
	        $save_button->setRequired(false)
	        			->setIgnore(true)
	        			->setLabel('Dodaj');
        }
        else
        {
	        $save_button = new Zend_Form_Element_Submit('save_button');
	        $save_button->setRequired(false)
	        			->setIgnore(true)
	        			->setLabel('Zapisz');
        }
        
        $save_button->setDecorators(
        	array(
    			array('ViewHelper')
			)
		);
        			
        $discard_button = new Zend_Form_Element_Button('discard_button');
        $discard_button->setRequired(false)
        			->setIgnore(true)
        			->setAttrib('onclick', 'window.location.href = \'/web/Manager\';')
        			->setLabel('Anuluj');
        
        $discard_button->setDecorators(
        	array(
    			array('ViewHelper')
			)
		);	

        $this->removeDecorator('Description');
        $this->addDecorator('Description', array('class' => '', 'placement' => 'prepend'));        			
		
		$this->setDescription('Dodaj kupon');
		
        $this->addElement($title)
        	->addElement($t_link)
        	->addElement($content)
        	->addElement($code)
        	->addElement($c_link)
        	->addElement($posted_date)
        	->addElement($expiry_date)
        	->addElement($category_id)
        	->addElement($file)
        	->addElement($password)
        	->addElement($id)
        	->addElement($form_id)
        	->addElement($token)
        	->addElement($save_button)
        	->addElement($discard_button)
        	->addDisplayGroup(array('save_button', 'discard_button'), 'buttons');
        	
        $buttons_group = $this->getDisplayGroup('buttons');
        $buttons_group->setDecorators(
        	array(
    			array('FormElements'),
			    array('HtmlTag', array('tag' => 'dd', 'class' => ''))
			)
		);        	
	}
}